#!/bin/bash
#功能函数
funcs=`which functions.sh`
if [ "$funcs" != "" ] ;then
    . $funcs
else
    funcs=`dirname $0`/functions.sh
    echo "$PWD"
    echo "funcs=$funcs"
    if [ "$funcs" != "" ] ;then
	. $funcs
    else
	exit
    fi
fi

sh_dpkg_install "curlftpfs sshpass"

machinenames="compiler001,compiler002,compiler003,compiler004,compiler005,compiler006,compiler007,compiler008"
function mount-sad8.sh()
{
    sudo cryptsetup luksOpen /dev/sda8 sda8
    sudo mount /dev/mapper/sda8 /opt
}

function unmount-sad8.sh()
{
sudo umount -f /opt/
sudo cryptsetup luksClose sda8
}

function mount_smartftp()
{
  echo "smart.shc -m mount smartftp  $config"
  smart.shc -m mount smartftp  $config
}
function mount_smartsvn()
{
  echo "smart.shc -m mount smartsvn $config"
  smart.shc -m mount smartsvn $config
}

function mount_smartupgrade()
{
  echo "smart.shc -m mount smartupgrade $config"
  smart.shc -m mount smartupgrade $config
}

function mount_smartftp_and_smartupgrade()
{
  mount_smartftp
  mount_smartupgrade
}

function mount_menu_select()
{
  smart.shc -m mount
}

function mount_all.sh
{
  if [ -n "$externel" ]; then
    for i in $externel
    do
      smart.shc -m mount $i $config
    done 
  else
    machinenames=`echo "$machinenames" | tr ',' ' '`
    machinenames="$machinenames smartftp smartupgrade"
    for machine in $machinenames
    do
      smart.shc -m mount $machine $config
    done
  fi
}

function unmount_all.sh()
{

  if [ -n "$externel" ]; then
    for i in $externel
    do
      smart.shc -m umount $i $config
    done 
  else
    machinenames=`echo "$machinenames" | tr ',' ' '`
    machinenames="$machinenames smartftp smartsvn"
    for machine in $machinenames
    do
      smart.shc -m umount $machine $config
    done
  fi

points=`mount |grep 172 |awk '{print $1}' |tr '\n' ' '`
points1=`mount |grep smartphone |awk '{print $3}' |tr '\n' ' '`
for point in $points
do
echo "sudo.shc umount  $point"
sudo.shc umount  $point
done
for point in $points1
do
echo "sudo.shc umount  $point"
sudo.shc umount  $point
done
}
#脚步入口：解析参数
while test $# != 0
do
    case $1 in
	--config)
	    shift
	    config=$1
	    ;;
	-m)
	    shift
	    mode=$1
	    ;;
        *)
	    externel="$1 $externel"
	    ;;
       esac
       shift
done

echo "externel=$externel"
externel="`echo $externel |tr ',' ' '`"
echo "config=$config"
if [ -n "$config" ]; then
  config="--config $config" 
fi
if [ "$mode" == "auto" ]; then
    echo "auto"
    setup-moban.sh
else
keyword="function"
menu_list="`cat /usr/local/bin/mount.sh  |grep $keyword | grep mount | tr -d "(|)" | awk '{print $2}'`"
    echoTextBlue "Please select"
    result=`sh_menu_select "$menu_list"`
    ${result}
fi

